using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using ZeroSum.App.Filters;

namespace ZeroSum.App.Extensions;

/// <summary>
///     友好化的返回格式
/// </summary>
public static class FriendlyResponseExtensions
{
    /// <summary>
    ///     注册友好化的返回数据格式
    /// </summary>
    /// <param name="builder"></param>
    /// <returns></returns>
    public static IMvcBuilder AddFriendlyResponse(this IMvcBuilder builder)
    {
        builder.AddMvcOptions(options => options.Filters.Add<ApiResponseFilter>());
        return builder;
    }

    /// <summary>
    ///     注册友好化的返回数据格式
    /// </summary>
    /// <returns></returns>
    public static IServiceCollection AddFriendlyResponse(this IServiceCollection serivces)
    {
        serivces.Configure<MvcOptions>(options => { options.Filters.Add<ApiResponseFilter>(); });
        return serivces;
    }
}